package com.zhl.utils;

import com.alibaba.druid.pool.DruidDataSource;

import java.util.Properties;

public class JdbcUtils {

    private DruidDataSource druidDataSource;

    private static class Holder{
        private static final JdbcUtils INSTANCE = new JdbcUtils();
    }

    private JdbcUtils(){
        druidDataSource = new DruidDataSource();
        Properties prop = new Properties();
        try {
            prop.load(this.getClass().getClassLoader().getResourceAsStream("jdbc.properties"));
           druidDataSource.setUsername(prop.getProperty("jdbc.username"));
           druidDataSource.setPassword(prop.getProperty("jdbc.password"));
           druidDataSource.setUrl(prop.getProperty("jdbc.url"));
           druidDataSource.setDriverClassName(prop.getProperty("jdbc.driverClassName"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static DruidDataSource getDataSource() {
        return Holder.INSTANCE.druidDataSource;
    }
}
